//具体观察目标类
var ConcreteSubject = /** @class */ (function () {
    function ConcreteSubject() {
        this.observers = [];
    }
    //添加观察者
    ConcreteSubject.prototype.addObserver = function (observer) {
        console.log(observer + "is pushed");
        this.observers.push(observer);
    };
    //移除观察者
    ConcreteSubject.prototype.deleteObserver = function (observer) {
        console.log(observer + "have deleted");
        var idx = this.observers.indexOf(observer);
        idx && this.observers.splice(idx, 1);
    };
    //通知观察者
    ConcreteSubject.prototype.notifyObservers = function () {
        console.log("notify all the observers" + this.observers);
        this.observers.forEach(function (observer) {
            observer.notify();
        });
    };
    return ConcreteSubject;
}());
//具体观察类
var ConcreteObserver = /** @class */ (function () {
    function ConcreteObserver(name) {
        this.name = name;
    }
    ConcreteObserver.prototype.notify = function () {
        console.log(this.name + " has been notified");
    };
    return ConcreteObserver;
}());
function useObserver() {
    var subject = new ConcreteSubject();
    var Leo = new ConcreteObserver("Leo");
    var Robin = new ConcreteObserver("Robin");
    var Pual = new ConcreteObserver("Pual");
    var Lisa = new ConcreteObserver("Lisa");
    subject.addObserver(Leo);
    subject.addObserver(Robin);
    subject.addObserver(Pual);
    subject.addObserver(Lisa);
    subject.notifyObservers();
    subject.deleteObserver(Pual);
    subject.deleteObserver(Lisa);
    subject.notifyObservers();
}
useObserver();
